package org.jtsmix.mixfile;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

//import java.io.InputStream;
//import java.io.OutputStream;

/**
 * @author Ivo Háleček
 */
public interface MixFile {

    /**
     * Load a mix archive.
     * <p/>
     * Must be run before any action.
     *
     * @param filePath mix archive to open
     * @param gameType game type
     * @throws FileNotFoundException
     * @throws IOException
     */
    public void open(String filePath, GameType gameType) throws FileNotFoundException, IOException;

    /**
     * Close the mix file stream.
     *
     * @throws IOException
     */
    public void close() throws IOException;

    /**
     * Extract the file from mix archive.
     *
     * @param fileName file name to extract
     * @return raw file data
     * @throws IOException
     */
    public byte[] read(String fileName) throws IOException;

    /**
     * Extract the file from mix archive and write it to output stream.
     *
     * @param fileName file name to extract
     * @param os       output stream to write in
     * @throws IOException
     * @returns false if no file with specified name found
     */
    public boolean read(String fileName, OutputStream os) throws IOException;

    /**
     * Extract the file from mix archive and load it to input stream.
     *
     * @param fileName file name to extract
     * @return extracted file stream
     * @throws IOException
     */
    public InputStream getFileStream(String fileName) throws IOException;

    /**
     * Extract the file from mix archive and load it to input stream.
     *
     * @param fileName file name to extract
     * @param os       output stream to fill with file raw data
     * @throws IOException
     */
    public void writeFileToStream(String fileName, OutputStream os) throws IOException;

    /**
     * Searches for the specified file name in mix archive.
     *
     * @param fileName file name to search
     * @returns false if file is not contained
     */
    public boolean contains(String fileName);

    /**
     * Write a new file to mix archive.
     *
     * @param fileName new file name
     * @param data     file raw data to write
     * @throws IOException
     */
    public void write(String fileName, byte[] data) throws IOException;

    /**
     * Removes a file from mix archive.
     *
     * @param fileName file name to delete
     * @throws IOException
     * @returns false if the specified file is not found in archive
     */
    public boolean remove(String fileName) throws IOException;

    /**
     * Get files headers contained in mix archive.
     *
     * @return list of MixFileIndexEntry headers
     */
    public List<MixFileIndexEntry> getFileList();

    /**
     * Searches for known file names from global mix database and returns a
     * list of them. If no name with same CRC is found, '#' character and CRC
     * string is returned.
     *
     * @return list of filenames
     */
    public List<String> getFileNameList();

    /**
     * Get summary information about the archive.
     *
     * @return summary information
     */
    public MixInfo getMixInfo();

    /**
     * @return true if opened
     */
    public boolean isOpened();
}